package com.pt.chitra.view.albumView.model
{
	import com.pt.chitra.config.ApplicationConfigs;
	import com.pt.chitra.config.ApplicationNotificationConstant;
	
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;

	public class GalleryProxy extends Proxy implements IProxy
	{
		public static const NAME:String = "GalleryProxy";

		public function GalleryProxy(data:Object=null)
		{
			//TODO: implement function
			super(NAME, data);
		}
		
		public function getGallries():void{
			 CursorManager.showCursor();
			 var galleryService:HTTPService = new HTTPService();
			 galleryService.url = ApplicationConfigs.domainURL;
			 galleryService.addEventListener(ResultEvent.RESULT,galleryResult);
			 galleryService.addEventListener(FaultEvent.FAULT,onFault);
			 galleryService.send();
		}
		
		private function galleryResult(e:ResultEvent):void{
			CursorManager.removeBusyCursor();
			sendNotification(ApplicationNotificationConstant.GET_GALLARY_INITAL_DATA_RESULT,e);
		}
		
		
		public function getGalleryImages(galleryID:int):void{
			 CursorManager.showCursor();
			 var galleryGetImagesService:HTTPService = new HTTPService();
			 galleryGetImagesService.url = ApplicationConfigs.allowDomainURL+"getImages.php?gallery_ID="+galleryID;
			 galleryGetImagesService.addEventListener(ResultEvent.RESULT,galleryGetImagesResult);
			 galleryGetImagesService.addEventListener(FaultEvent.FAULT,onFault);
			 galleryGetImagesService.send();
			 /*  id="imageService"
       	 	result="getImagesHandler(event);"
        	fault="faultHandler(event);" */
		}
		
		private function galleryGetImagesResult(e:ResultEvent):void{
			CursorManager.removeBusyCursor();
			sendNotification(ApplicationNotificationConstant.GET_GALLARY_IMAGES_DATA_RESULT,e);
		}
		
		private function onFault(fault:FaultEvent):void{
			CursorManager.removeBusyCursor();
			mx.controls.Alert.show(fault.fault.faultString, fault.fault.faultCode.toString());
		}	
		
		
	}
}